﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Text
{
    class DbHelp
    {
        private static readonly string ConString = "server=.;database=Admin;uid=sa;pwd=123456;";

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="sql">select语句</param>
        /// <returns>数据</returns>
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(ConString);

            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sql, sqlConnection);

            DataTable dt = new DataTable();

            sqlConnection.Open();

            sqlDataAdapter.Fill(dt);

            return dt;
        }

        public static int AddOrEditOrDeleteSave(string sql)
       {
            SqlConnection sqlConnection = new SqlConnection(ConString);

            SqlCommand sqlCommand = new SqlCommand(sql,sqlConnection);

            sqlConnection.Open();

            return sqlCommand.ExecuteNonQuery();
        }
    }
}
